<?php
class DigCms_View_Helper_DigCmsRenderItem extends Zend_View_Helper_Abstract
{
    /**
     * this helper renders an item from the site tree
     *
     * it maps the items based on name (as oposed to the label in menus)
     *
     * The item can either be the primary key, a DigCms_Model_Item, or a path to the item
     *
     * @param string $item
     * @param bool $enableCache
     */
    public function digCmsRenderItem($item, $enableCache = true, $refreshCache = false) {
        if(! $item instanceof DigCms_Model_Item) {
            if(is_int($item)) {
                // create a new item to work with
                $item = DigCms_Model_Item::factory($item);
            } else {
                // try to map this as a path
                $item = DigCms_Service_Item::getItemByPath($path);
            }
        }
        
        if(! $item) {
            return false;
        }
        
        $itemType = DigCms_Service_Item::getItemType($item);
        if(is_array($itemType)) {
            $path = '/' . $itemType['module'] . '/' . $itemType['controller'] . '/render';
            $params = array('DigCms_Item' => $item);
            return $this->view->digUiBlock($path, $params, $enableCache, $refreshCache);
        }
    }
}
?>
